home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Gamma Gun.lua < prev    next >
Text File  |  2010-08-31  |  7KB  |  180 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Gamma Gun + Projectile Ray
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.gammagun={}
  10. cc.gammagun.ray={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.gammagun.gfx_wpn=loadgfx("weapons/gammagun.bmp")                    -- Weapon Image
  14. setmidhandle(cc.gammagun.gfx_wpn)
  15. cc.gammagun.gfx_pro=loadgfx("weapons/lasershot.png")                -- Projectile Image
  16. setmidhandle(cc.gammagun.gfx_pro)
  17. cc.gammagun.sfx_attack=loadsfx("laser.wav")                            -- Attack Sound
  18. cc.gammagun.sfx_impact=loadsfx("laserimpact.wav")                    -- Impact Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: Gamma Gun
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.gammagun.id=addweapon("cc.gammagun","Gamma Gun",cc.gammagun.gfx_wpn,0)    -- Add Weapon (0 uses)
  25. cc.gammagun.ammo=3                                                            -- 3 Shots
  26.  
  27. function cc.gammagun.draw()                                        -- Draw
  28.     setblend(blend_alpha)
  29.     setalpha(1)
  30.     setcolor(255,255,255)
  31.     drawinhand(cc.gammagun.gfx_wpn,6,0)
  32.     -- HUD ammobar
  33.     if cc.gammagun.ammo-weapon_shots>0 then
  34.         hudammobar(cc.gammagun.ammo-weapon_shots,cc.gammagun.ammo)
  35.     end
  36.     -- HUD Crosshair
  37.     if cc.gammagun.ammo-weapon_shots>0 then
  38.         hudcrosshair(7,3)
  39.     end
  40. end
  41.  
  42. function cc.gammagun.attack(attack)                                -- Attack
  43.     -- Decrement timer
  44.     if weapon_timer>0 then
  45.         weapon_timer=weapon_timer-1
  46.     end
  47.     -- Attack
  48.     if weapon_shots<cc.gammagun.ammo and weapon_timer<=0 and attack==1 then
  49.         -- No more weapon switching!
  50.         useweapon(0)
  51.         -- Reset Timer
  52.         weapon_timer=15
  53.         -- Attack
  54.         playsound(cc.gammagun.sfx_attack)
  55.         weapon_shots=weapon_shots+1
  56.         id=createprojectile(cc.gammagun.ray.id)
  57.         projectiles[id]={}
  58.         -- Ignore collision with current player at beginning
  59.         projectiles[id].ignore=playercurrent()
  60.         -- Set initial position of projectile
  61.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  62.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  63.         -- Set speed of projectile
  64.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*6.0
  65.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*6.0
  66.         -- Timer
  67.         projectiles[id].timer=0
  68.         -- Initial movement
  69.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  70.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  71.         for i=1,3,1 do
  72.             if cc.gammagun.ray.move(id)==1 then
  73.                 break
  74.             end
  75.         end
  76.         -- Effects
  77.         recoil(3)
  78.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  79.         particlecolor(255,255,0)
  80.         particlefadealpha(0.01)
  81.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*12,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*12)
  82.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  83.         particlefadealpha(0.005)
  84.         -- End Turn
  85.         if (weapon_shots>=cc.gammagun.ammo) then
  86.             endturn()
  87.         end
  88.     end
  89. end
  90.  
  91. --------------------------------------------------------------------------------
  92. -- Projectile: Ray
  93. --------------------------------------------------------------------------------
  94.  
  95. cc.gammagun.ray.id=addprojectile("cc.gammagun.ray")            -- Add Projectile
  96.  
  97. function cc.gammagun.ray.draw(id)                            -- Draw
  98.     -- Setup draw mode
  99.     setblend(blend_light)
  100.     setalpha(1)
  101.     setcolor(255,255,0)
  102.     setscale(1.0,0.5)
  103.     -- Calculate projectile rotation
  104.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  105.     -- Draw projectile
  106.     drawimage(cc.gammagun.gfx_pro,projectiles[id].x,projectiles[id].y)
  107.     -- Draw Arrow if out of Screen
  108.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  109. end
  110.  
  111. function cc.gammagun.ray.update(id)                            -- Update
  112.     -- Particle Tail
  113.     particle(p_lightpuff,projectiles[id].x,projectiles[id].y)
  114.     particlespeed(math.random(-5,5)*0.1,math.random(-5,5)*0.1)
  115.     particlefadealpha(0.05)
  116.     particlesize(math.random(20,40)*0.1,math.random(20,40)*0.1)
  117.     particlecolor(255,175,0)
  118.     -- Move
  119.     cc.gammagun.ray.move(id)
  120. end
  121.  
  122. function cc.gammagun.ray.move(id)
  123.     -- Timer (free after 10 secs)
  124.     projectiles[id].timer=projectiles[id].timer+1
  125.     if projectiles[id].timer>500 then
  126.         -- Free projectile
  127.         freeprojectile(id)
  128.         return 1
  129.     end
  130.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  131.     -- Move (in substep loop for optimal collision precision)
  132.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  133.     msubx=projectiles[id].sx/msubt
  134.     msuby=projectiles[id].sy/msubt
  135.     for i=1,msubt,1 do
  136.         projectiles[id].x=projectiles[id].x+msubx
  137.         projectiles[id].y=projectiles[id].y+msuby        
  138.         -- Collision
  139.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5,0,1,1)==1 then
  140.             if playercollision()~=projectiles[id].ignore or objectcollision()>0 then
  141.                 -- Cause damage and Push
  142.                 if playercollision()~=projectiles[id].ignore and playercollision()>0 then
  143.                     playerdamage(playercollision(),15)
  144.                     playerpush(playercollision(),projectiles[id].sx/6.5,projectiles[id].sy/6.5)
  145.                 else
  146.                     objectdamage(objectcollision(),15)
  147.                 end
  148.                 -- Effects
  149.                 playsound(cc.gammagun.sfx_impact)
  150.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  151.                 particlefadealpha(0.006)
  152.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  153.                 particlesize(1.5,1.5)
  154.                 particlecolor(255,255,0)
  155.                 particlefadealpha(0.01)
  156.                 for j=1,20,1 do
  157.                     particle(p_lightpuff,projectiles[id].x+math.sin(math.rad(rot))*5,projectiles[id].y-math.cos(math.rad(rot))*5)
  158.                     particlespeed(math.random(-20,20)*0.1,math.random(-20,20)*0.1)
  159.                     particlefadealpha(0.04)
  160.                     particlesize(math.random(40,70)*0.1,math.random(40,70)*0.1)
  161.                     particlecolor(255,200,0)
  162.                 end
  163.                 -- Free projectile
  164.                 freeprojectile(id)
  165.                 return 1
  166.             end
  167.         else
  168.             projectiles[id].ignore=0
  169.         end
  170.         -- Water
  171.         if (projectiles[id].y)>getwatery()+5 then
  172.             -- Effects
  173.             playsound(cc.gammagun.sfx_impact)
  174.             particle(p_smoke,projectiles[id].x,projectiles[id].y)
  175.             -- Free projectile
  176.             freeprojectile(id)
  177.             return 1
  178.         end
  179.     end
  180. end